//此文件是 axios 的二次封装
//引入 axios
import axios from "axios";

//页面加载进度条
import nprogress from "nprogress";
import "nprogress/nprogress.css";

//axios实例对象
let requests = axios.create({
  //基础路径
  baseURL: "/eleven",
  //请求不能超过5S
  timeout: 5000,
});

//请求拦截器
requests.interceptors.request.use((config)=>{
  //加载条滚动
  nprogress.start()

  return config
},(error)=>{
    return console.warn('请求失败',error)
})

//响应拦截器
requests.interceptors.response.use((response)=>{
  //加载条结束
  nprogress.done()

  return response.data
},(error)=>{
    return console.log('响应失败',error)
})

//暴露 axios 实例
export default requests;